package com.voja.mrvica2.listener;

import com.voja.mrvica2.Entry;
import com.voja.mrvica2.Index;
import com.voja.mrvica2.R;
import com.voja.mrvica2.fragment.DetailsFragment;

import android.app.FragmentManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

public class ItemClickListener implements ListView.OnItemClickListener {
    
    Index activity;
    
    public ItemClickListener(Index activity) {
        this.activity = activity;
    }
    
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        FragmentManager manager = activity.getFragmentManager();
        Entry           entry   = Index.items.get(position);
        
        Index.detailsFragment = new DetailsFragment();
        Index.detailsFragment.setParams(activity, entry);
        
        manager.beginTransaction()
               .replace(R.id.details_frame, Index.detailsFragment)
               .commit();
        activity.setShareProvider();
        
        activity.showDetails();
    }
}
